<template>
	<view>
		<cu-custom bgColor="bg-gradual-fff" isBack="true">
			<block slot="content">会员核销</block>
		</cu-custom>
		<loading-view v-if="showLoading"></loading-view>
		<view class="layout" v-show="!showLoading" v-if="UserDetail!=''">
			<view class="viewbox"></view>
			<!-- <view class="user_writeoff_a_b">
				用户名：{{UserDetail.nickname}}----------电话：{{UserDetail.mobile}}
			</view> -->
			<view class="user_writeoff_aa">
				<view class="user_writeoff_a">
					<view class="user_writeoff_a_a">用户</view>
					<view class="user_writeoff_a_b">
						{{UserDetail.nickname}}--{{UserDetail.mobile}}
					</view>
				</view>

				<!-- <view class="user_writeoff_b_b">
					<input style="background: #d2e9ef; width: 100%; height: 100%; 
				padding-left: 30rpx;" type="number" v-model="amount" placeholder="输入金额"></input>
				</view> -->
				<!-- 金额 -->
				<view class="user_writeoff_b" v-if="id===''">
					<view class="user_writeoff_b_a">需核销积分</view>
					<view class="user_writeoff_b_b">
						<input type="number" v-model="amount" placeholder="输入积分"></input>
					</view>
				</view>
				<view class="user_writeoff_b" v-if="id!==''">
					<view class="user_writeoff_b_a">核销订单id</view>
					<view class="user_writeoff_b_b">
						<view type="number"> {{ id }}</view>
					</view>
				</view>
			</view>

			<view class="user_writeoff_ab" @click="handleVerificationConfirm" v-if="id===''">点击核销</view>
			<view class="user_writeoff_ab" @click="hexiao" v-if="id!==''">核销订单</view>
		</view>
		<view v-else>
			<view class="details-null column-center">
				<image class="img-null" src="/static/goods_null.png"></image>
				<view class="xs muted">抱歉，该用户不存在！</view>
			</view>
		</view>
	</view>
</template>
<script>
	import api from '../../common/apiService';
	import request from '../../common/request';
	const {
		getUserIntegral
	} = api;

	import {
		loadingType
	} from '@/utils/type';
	export default {
		data() {
			return {
				UserDetail: [],
				amount: "",
				uid: 0,
				mid: 0,
				showLoading: true,
				// selffetch_shop_id:0,
				// pickup_code:0,
				id:0
			}
		},
		onLoad() {
			const mid = uni.getStorageSync('mid');
			this.mid = mid
			console.log("mid为", mid)
			this.uid = uni.getStorageSync('uid');
			this.id = uni.getStorageSync('id');
			this.loginfo();
		},
		onShow() {},
		methods: {
			// 获取用户信息
			loginfo() {
				const uid = uni.getStorageSync('uid');
				getUserIntegral(uid).then(res => {
					this.UserDetail = res;
					console.log("得到的用户信息", this.UserDetail);
				}).catch(e => {
					console.log("另一个信息", e);
				}).finally(() => {
					this.showLoading = false
				})
			},
			handleVerificationConfirm() {
				uni.request({
					url: request.baseUrl + 'm-ConfirmScan',
					method: 'POST',
					header: {
						'Content-Type': 'application/json'
					},
					data: {
						mid: this.mid,
						uid: this.uid,
						amount: this.amount
					},
					success(res) {
						console.log("得到", res)

						if (res.data.code === 200) {
							uni.showToast({
								title: res.data.data.msg,
								icon: 'success'
							}).then(() => {
								setTimeout(() => {
									uni.redirectTo({
										url: '/pages/index/index'
									})
								}, 1500)
							}).finally(() => {
								uni.removeStorageSync('uid');
							})
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'error'
							}).then(() => {
								setTimeout(() => {
									uni.redirectTo({
										url: '/pages/index/index'
									})
								}, 1500)
							})
						}
					}
				})
			},
			hexiao(){
				uni.request({
					url:request.baseUrl +'o-order_write_off_confirm',
					// url:request.baseUrl+'o-order_write_off',
					method:'POST',
					header: {
						'Content-Type': 'application/json'
					},
					data: {
						mid: this.mid,
						uid: this.uid,
						id: this.id
						// selffetch_shop_id:2
						// pickup_code:123
					},
					success(res) {
						console.log("第二",res);
						if (res.data.code === 200) {
							uni.showToast({
								title: res.data.data,
								icon: 'success'
							}).then(() => {
								setTimeout(() => {
									uni.redirectTo({
										url: '/pages/index/index'
									})
								}, 1500)
							}).finally(() => {
								uni.removeStorageSync('uid');
							})
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'error'
							}).then(() => {
								setTimeout(() => {
									uni.redirectTo({
										url: '/pages/index/index'
									})
								}, 1500)
							})
						}
					}
				})
			}
			
			
		}
	}
</script>

<style lang="scss" scoped>
	.layout {
		.user_writeoff_aa {
			width: 750rpx;
			height: auto;
			padding: 0 20rpx;
			background-color: #fff;
			margin-top: 20rpx;
			padding-bottom: 30rpx;
		}

		.user_writeoff_a {
			height: 100rpx;
			line-height: 100rpx;
			overflow: hidden;
			width: 100%;
			border-bottom: 1rpx solid #E8E8E8;
		}

		.user_writeoff_a_a {
			float: left;
			font-family: Alibaba PuHuiTi 2.0;
			font-size: 28rpx;
			color: #666666;
		}

		.user_writeoff_a_b {
			float: right;
			font-family: Alibaba PuHuiTi 2.0;
			font-size: 28rpx;
			color: #333;
		}

		.user_writeoff_b {
			overflow: hidden;
		}

		.user_writeoff_b_a {
			height: 100rpx;
			line-height: 100rpx;
			overflow: hidden;
			width: 100%;
			font-family: Alibaba PuHuiTi 2.0;
			font-size: 28rpx;
			color: #666666;
		}

		.user_writeoff_b_b {
			overflow: hidden;
		}















		// .user_writeoff_a_b {
		// 	width: 710rpx;
		// 	height: 100rpx;
		// 	// border: 1px solid red;
		// 	margin: 100rpx 20rpx 0 20rpx;
		// 	font-size: 25rpx;
		// 	color: #000000;
		// 	font-weight: 600;
		// 	box-sizing: border-box;
		// 	border-radius: 20rpx;
		// 	background: #ffffff;
		// 	padding: 30rpx 0 0 100rpx;
		// }

		// .user_writeoff_b_b {
		// 	width: 710rpx;
		// 	height: 100rpx;
		// 	// border: 1px solid red;
		// 	border-radius: 40rpx;
		// 	margin: 50rpx 20rpx 0 20rpx;
		// }

		.user_writeoff_ab {
			// width: 300rpx;
			// height: 120rpx;
			// margin: 50rpx 0 0 250rpx;
			// // border: 1px solid red;
			// border-radius: 30rpx;
			// background: rgba(110, 173, 255, 0.5);
			// font-size: 30rpx;
			// font-weight: 500;
			// box-sizing: border-box;
			// padding: 40rpx 0 0 90rpx;
			width: 710rpx;
			height: 90rpx;
			line-height: 90rpx;
			text-align: center;
			margin: auto;
			margin-top: 40rpx;
			font-family: Source Han Sans;
			font-size: 34rpx;
			font-weight: normal;
			color: #FFFFFF;
			background-color: #1e3880;
			border-radius: 200rpx;
		}

	}
</style>